Threading

The ODBC specification requires that all ODBC drivers must be thread-safe; that is, they must not fail when database requests are made on separate threads.

Threading Architecture

An ODBC driver can be based on one of the following architectures:

The ODBC driver supports multithreaded applications on all platforms.

Cancelling Functions in Multithreaded Applications

In a multithreaded application, the application can cancel a function that is running synchronously on a statement. To cancel the function, the application calls SQLCancel with the same statement handle as that used by the target function, but on a different thread. Whether SQLCancel actually cancels the running function depends on the data store being accessed as shown in Table 2-7.

In both cases, SQLCancel returns SQL_SUCCESS. If SQLCancel has been called from a different thread while there is a pending request, the original statement will return SQL_ERROR with the error message Operation cancelled.

Table 2-7. Using SQLCancel in Multithreaded Applications
Data Store
SQLCancel
DB2 UDB on Windows
OK
DB2 UDB on Linux and UNIX
Ignored
Informix
OK
Microsoft SQL Server
OK
Oracle on Windows
Ignored
Oracle on Linux and UNIX
OK
Sybase
OK